package com.fz.us.oa.web.shiro.filter;

import com.fz.us.admin.base.utils.LogUtil;
import com.fz.us.oa.web.shiro.Constants;
import com.fz.us.oa.web.shiro.service.ShiroService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * <p>User: Zhang Kaitao
 * <p>Date: 14-2-15
 * <p>Version: 1.0
 */
public class SysUserFilter extends PathMatchingFilter {

    @Autowired
    private ShiroService shiroService;

    @Override
    protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
        String adminId = (String) SecurityUtils.getSubject().getPrincipal();
       // LogUtil.info("adminId:"+adminId);
       // System.out.println("adminId:"+adminId);
        request.setAttribute(Constants.CURRENT_USER, shiroService.getUserByAdminId(adminId));
        return true;
    }

}
